package com.bxd.baodan.widget;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Display;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;

import com.bxd.baodan.R;

public class InsureHelperDialog extends Dialog implements View.OnClickListener {
	private String title;
	private String content;
	private String firstButtonContent;
	private String secondButtonContent;
	private Button firstButton;
	private Button secondButton;
//	private ImageView cancelImageView;
	private TextView titleTextView;
	public TextView getTitleTextView() {
		return titleTextView;
	}
	public void setTitleTextView(TextView titleTextView) {
		this.titleTextView = titleTextView;
	}
	public TextView getContentTextView() {
		return contentTextView;
	}
	public void setContentTextView(TextView contentTextView) {
		this.contentTextView = contentTextView;
	}
	private TextView contentTextView;
	private View line_gray;
	private Context context;
	private CostumWidgetClickListener costumClick;
	public CostumWidgetClickListener getOnClickListener() {
		return costumClick;
	}
	public void setCostumClick(CostumWidgetClickListener onClickListener) {
		this.costumClick = onClickListener;
	}
	public InsureHelperDialog(Context context) {
		super(context);
	}
	public InsureHelperDialog(Context context, String title, String content,
			  String firstButtonContent,
			String secondButtonContent) {
		super(context);
		this.context = context;
		this.title = title;
		this.content = content;
		this.firstButtonContent = firstButtonContent;
		this.secondButtonContent = secondButtonContent;
		this.setCancelable(false);
		
	}
	/**两个button，没有监听*/
	public static InsureHelperDialog getShowDailog(Context context,
			String title, String content ) {
		InsureHelperDialog ihDialog = new InsureHelperDialog(context, title,
				content, null, null);
		ihDialog.setCancelable(true);
		return ihDialog;
	}

	public static InsureHelperDialog getShowDailog(Context context,
			String title, String content, String firstButtonContent) {
		InsureHelperDialog ihDialog=  new InsureHelperDialog(context, title, content,
				firstButtonContent, null);
		ihDialog.setCancelable(false);
		return ihDialog;
	}

	public static InsureHelperDialog getShowDailog(Context context,
			String title, String content, String firstButtonContent,
			String secondButtonContent, CostumWidgetClickListener listener) {
		InsureHelperDialog dialog = new InsureHelperDialog(context, title,
				content, firstButtonContent, secondButtonContent);
		dialog.setCostumClick(listener);
		dialog.setCancelable(false);
		return dialog;
	}
	public static InsureHelperDialog getShowDailogWithoutTitle(Context context,
			String content, String firstButtonContent) {
		InsureHelperDialog dialog = new InsureHelperDialog(context, null, content,
				firstButtonContent, null);
		dialog.setCancelable(false);
		return dialog;
	}
	
	public static InsureHelperDialog getShowDailogWithoutTitle(Context context,
			  String content, String firstButtonContent,
			String secondButtonContent, CostumWidgetClickListener listener) {
		InsureHelperDialog dialog = new InsureHelperDialog(context, null,
				content, firstButtonContent, secondButtonContent);
		dialog.setCostumClick(listener);
		dialog.setCancelable(false);
		return dialog;
	}

	public static InsureHelperDialog getShowDailog(Context context,
			String title, String content, String firstButtonContent,
			CostumWidgetClickListener listener) {
		InsureHelperDialog dialog = new InsureHelperDialog(context, title,
				content, firstButtonContent, null);
		dialog.setCostumClick(listener);
		dialog.setCancelable(false);
		return dialog;
	}
    //dialog.setCanceledOnTouchOutside(false);//设置点击空白区域不取消
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		this.setContentView(R.layout.custom_dialog_box);
		initViews();
	}
	private void initViews() {
//		this.cancelImageView = (ImageView) this.findViewById(R.params.cancel_imageView);
		this.firstButton = (Button) this.findViewById(R.id.button_first);
		this.secondButton = (Button) this.findViewById(R.id.button_second);
		this.titleTextView = (TextView) this.findViewById(R.id.dialog_title);
		this.contentTextView = (TextView) this.findViewById(R.id.dialog_content);
		this.line_gray = this.findViewById(R.id.line_gray);
		if(this.title == null){
			this.titleTextView.setVisibility(View.GONE);
			this.line_gray.setVisibility(View.GONE);
		}else{
			this.titleTextView.setText(title);
		}
		if(this.content == null){
			this.contentTextView.setVisibility(View.GONE);
		}else{
			this.contentTextView.setText(content);
			
		}
		if(this.firstButtonContent == null){
			this.firstButton.setVisibility(View.GONE);
		}else{
			firstButton.setText(this.firstButtonContent);
		}
		if(this.secondButtonContent == null){
			this.secondButton.setVisibility(View.GONE);
		}else{
			this.secondButton.setText(this.secondButtonContent);
			
		}
//		this.cancelImageView.setOnClickListener(this);
		this.firstButton.setOnClickListener(this);
		this.secondButton.setOnClickListener(this);
		WindowManager m = ((Activity)context).getWindowManager();
		Display d = m.getDefaultDisplay(); // 获取屏幕宽、高用
		WindowManager.LayoutParams p = getWindow().getAttributes(); // 获取对话框当前的参数值
		p.width = (int) (d.getWidth() * 0.9); // 宽度设置为屏幕的0.95
		this.getWindow().setAttributes(p);
	}
	public interface CostumWidgetClickListener{
		abstract void onFirstButtonClick();
		abstract void onSecondButtonClick();
		abstract void onCancelButtonClick();
	}
	@Override
	public void onClick(View view) {
		 switch(view.getId()){
//		 case R.params.cancel_imageView:
//			 costumClick.onCancelButtonClick();
//			 break;
		 case R.id.button_first:
			 costumClick.onFirstButtonClick();
			 break;
		 case R.id.button_second:
			 costumClick.onSecondButtonClick();
			 break;
		 }
		 this.cancel();
	}
	
	
	
}
